<template>
  <div>
    <h1>这是列表页面</h1>
    <el-button type="primary" @click="addList()">添加</el-button>
    <!-- 搜索 -->

    <el-form ref="pageInfo" :inline="true" :model="form">
      <el-form-item label="组织名称" style="width: 40%">
        <el-input v-model="pageInfo.keyWord"></el-input>
      </el-form-item>
      <el-form-item label="组织编码" style="width: 40%">
        <el-input v-model="pageInfo.num"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="序号" width="80" type="index"> </el-table-column>
      <el-table-column label="组织编码" width="80">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.scenNum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="阻止名称" width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.scenName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上级组织" width="100">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.firName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="排序" width="50">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.orderss }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最近修改" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.updateTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" width="180">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="deleteById(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[3, 5, 7]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { userlist, userDele } from "@/api/userApi";
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      tableData: [],
      pageInfo: {
        beginTime: null,
        endTime: null,
        keyWord: null,
        pageNum: 1,
        pageSize: 3,
        num: null,
      },
      total: 0,
    };
  },
  created() {
    this.list();
  },
  methods: {
    list() {
      userlist(this.pageInfo).then((res) => {
        this.tableData = res.data.data.list;
        this.total = res.data.data.total;
      });
    },
    //分页
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.list();
    },
    deleteById(index, row) {
      userDele(row.scenId).then((res) => {
        this.$message.success(res.data.data);
        this.list();
      });
    },
    addList() {
      this.$router.push("/add");
    },
  },
};
</script>

<style scoped></style>
